Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default the resolved customer to the current user #787

Merged

Conversation

justlevine
Copy link
Contributor

@justlevine justlevine commented Aug 21, 2023

Your checklist for this pull request

Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.

🚨Please review the guidelines for contributing to this repository.

  • Make sure you are making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Make sure you are requesting to pull request from a topic/feature/bugfix/devops branch (right side). Don't pull request from your master!
  • Have you ensured/updated that CLI tests to extend coverage to any new logic. Learn how to modify the tests here.

What does this implement/fix? Explain your changes.

This PR fixes the RootQuery.customer query to default to the current user. This prevents mismatches where the user is logged in, but the customer is still a guest session.

The underlying issue is that the customer resolver was previously only using the existing woocommerce-session (if it exists) or an explicit id passed by as an arg, but never the current authenticated user's ID. This could lead to a situation (first-time queries usually) where a user is authenticated with an Authorization header, but the customer is a guest session.

After the change, the resolver defaults to using the current user id, and will only fallback to the guest session if no user is logged in.

Does this close any currently open issues?

Not that I know of.

Any relevant logs, error output, GraphiQL screenshots, etc?

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

Any other comments?

Didn't add a unit test for this since I cant get the test env running, but it should essentially:

  1. wp_set_current_user( $some_user );
  2. run this query
query {
  customer {
    id
    databaseId
  }
  viewer {
    databaseId
  }
}
  1. Ensure customer.id !== 'guest' and customer.databaseId === viewer.databaseId === the logged in user.

Where has this been tested?

  • WooGraphQL Version: dev-develop
  • WPGraphQL Version: 1.14.10
  • WordPress Version: 6.3
  • WooCommerce Version: 8.0.2

Copy link
Member

@kidunot89 kidunot89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justlevine Good catch, bro

@kidunot89 kidunot89 merged commit c59aec7 into wp-graphql:develop Aug 23, 2023
14 checks passed
@kidunot89 kidunot89 added the bugfix Implements bugfix label Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Implements bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants